#include "Inventory.h"
#include "Gladiator.h"

#include <iostream>
#include <iomanip>
using namespace std;

Inventory::Inventory()
{
	size = 14;

	itemNames[0] = "Common Sword";		itemNames[1] = "Fine Sword";
	itemNames[2] = "Grand Sword";		itemNames[3] = "Bastard Sword";
	itemNames[4] = "Diamond Blade";		itemNames[5] = "Wooden Shield";		
	itemNames[6] = "Copper Shield";		itemNames[7] = "Silver Shield";		
	itemNames[8] = "Golden Shield";		itemNames[9] = "Diamond Shield";
	itemNames[10] = "Health Pack";		itemNames[11] = "Large Health Pack";
	itemNames[12] = "Mega Health Pack";	itemNames[13] = "Perfect Health Pack";

	itemCost[0] = 50;			itemCost[1] = 100;
	itemCost[2] = 250;			itemCost[3] = 750;
	itemCost[4] = 1500;			itemCost[5] = 50;
	itemCost[6] = 100;			itemCost[7] = 250;
	itemCost[8] = 750;			itemCost[9] = 1500;
	itemCost[10] = 10;			itemCost[11] = 30;
	itemCost[12] = 60;			itemCost[13] = 100;

	//initialize items owned to zero
	for(int i = 0; i < size; i++)
	{
		itemInv[i] = 0;
	}

	itemType[0] = 'w';			itemType[1] = 'w';
	itemType[2] = 'w';			itemType[3] = 'w';
	itemType[4] = 'w';			itemType[5] = 'a';
	itemType[6] = 'a';			itemType[7] = 'a';
	itemType[8] = 'a';			itemType[9] = 'a';
	itemType[10] = 'h';			itemType[11] = 'h';
	itemType[12] = 'h';			itemType[13] = 'h';

	itemBoost[0] = 15;			itemBoost[1] = 30;
	itemBoost[2] = 50;			itemBoost[3] = 75;
	itemBoost[4] = 100;			itemBoost[5] = 15;
	itemBoost[6] = 30;			itemBoost[7] = 50;
	itemBoost[8] = 75;			itemBoost[9] = 100;
	itemBoost[10] = 25;			itemBoost[11] = 50;
	itemBoost[12] = 100;		itemBoost[13] = 290; //290 is Max Level HP

	equipNum[0] = 1;			equipNum[1] = 2;
	equipNum[2] = 3;			equipNum[3] = 4;
	equipNum[4] = 5;			equipNum[5] = 6;
	equipNum[6] = 7;			equipNum[7] = 8;
	equipNum[8] = 9;			equipNum[9] = 10;
	equipNum[10] = 11;			equipNum[11] = 12;
	equipNum[12] = 13;			equipNum[13] = 14;

	equippedWeapon = 0;
	equippedArmor = 0;

	itemSell[0] = 35;			itemSell[1] = 70;
	itemSell[2] = 175;			itemSell[3] = 525;
	itemSell[4] = 1050;			itemSell[5] = 35;
	itemSell[6] = 70;			itemSell[7] = 175;
	itemSell[8] = 525;			itemSell[9] = 1050;
	itemSell[10] = 7;			itemSell[11] = 21;
	itemSell[12] = 42;			itemSell[13] = 70;

	reqLevel[0] = 1;			reqLevel[1] = 3;
	reqLevel[2] = 7;			reqLevel[3] = 10;
	reqLevel[4] = 14;			reqLevel[5] = 1;
	reqLevel[6] = 3;			reqLevel[7] = 7;
	reqLevel[8] = 10;			reqLevel[9] = 14;
	reqLevel[10] = 1;			reqLevel[11] = 1;
	reqLevel[12] = 1;			reqLevel[13] = 1;

}

//shop menu
void Inventory::shopMenu()
{
	cout << setw(34) << left << " " << "REQUIRED" << endl;
	cout << setw(5) << left << "#" << setw(22) << "ITEM" << setw(9) << left << "COST" << "LEVEL" << endl;
	for(int i = 0; i < size; i++)
	{
	cout << setw(5) << left << (i + 1) << setw(22) << left << itemNames[i] << setw(4) << right  << itemCost[i] <<
		setw(6) << left << " " << setw(2) << right << reqLevel[i] << endl;
	}
}

//print current inventory
void Inventory::printInv()
{
	bool itemsFound = false;

	cout << "CURRENT INVENTORY" << endl;
	cout << "--------------------------------" << endl;
	cout << setw(25) << left << "ITEM" << setw(7) << left << "#" << "EQUIPPED" << endl;

	for(int i = 0; i < size; i++)
	{
		//if you own at least one of the item
		if(itemInv[i] > 0)
		{
			//output item name and quantity
			cout << setw(22) << left << itemNames[i] << " " << setw(4) << right  << itemInv[i];
			if(itemType[i] == 'w')
			{
				if(equippedWeapon == equipNum[i])
					cout << setw(10) << left << " " << "X";
				else
					cout << setw(10) << left << " " << "-";

			}
			else if (itemType[i] == 'a')
			{
				if(equippedArmor == equipNum[i])
					cout << setw(10) << left << " " << "X";
				else
					cout << setw(10) << left << " " << "-";
			}
			else
				cout << setw(10) << left << " " << "-";
			cout << endl;
			itemsFound = true;
		}
	}

	if(itemsFound == false)
	{
		cout << setw(22) << left << "0" << " " << setw(4) << right  << "0";
		cout << setw(10) << left << " " << "-" << endl;
		cout << "\n\nNo items in inventory" << endl;
	}
}

//manually set inventory values
void Inventory::setInv(int one, int two, int three, int four, int five, int six, 
					   int seven, int eight, int nine, int ten, int eleven, int twelve,
					   int thirteen, int fourteen)
{
	itemInv[0] = one;
	itemInv[1] = two;
	itemInv[2] = three;
	itemInv[3] = four;
	itemInv[4] = five;
	itemInv[5] = six;
	itemInv[6] = seven;
	itemInv[7] = eight;
	itemInv[8] = nine;
	itemInv[9] = ten;
	itemInv[10] = eleven;
	itemInv[11] = twelve;
	itemInv[12] = thirteen;
	itemInv[13] = fourteen;
}

//increment inventory
void Inventory::incrementInv(int x)
{
	itemInv[x]++;
}

//return item cost
int Inventory::getCost(int x)
{
	return itemCost[x];
}

//return item name
string Inventory::getName(int x)
{
	return itemNames[x];
}

//return inventory
int Inventory::getInv(int x)
{
	return itemInv[x];
}

//return weapon type
char Inventory::getType(int x)
{
	return itemType[x];
}

//return equip number
int Inventory::getEquipNum(int x)
{
	return equipNum[x];
}

//return item boost value
int Inventory::getItemBoost(int x)
{
	return itemBoost[x];
}

//return equipped items number
int Inventory::getEquipWeap()
{
	return equippedWeapon;
}

//set equip item number
void Inventory::setEquipWeap(int num)
{
	equippedWeapon = num;
}

//return equipped items number
int Inventory::getEquipArm()
{
	return equippedArmor;
}

//set equip item number
void Inventory::setEquipArm(int num)
{
	equippedArmor = num;
}

//return sell price
int Inventory::getSell(int x)
{
	return itemSell[x];
}

//display menu for selling items
int Inventory::sellMenu()
{
	int numOfItems = 0;
	int n = 1;

	cout << "CURRENT INVENTORY" << endl;
	cout << "--------------------------------" << endl;
	cout << setw(5) << left << "#" << setw(25) << left << "ITEM" << setw(7) << left << "QTY" << "SELL PRICE" << endl;

	for(int i = 0; i < size; i++)
	{
		//if you own at least one of the item
		if(itemInv[i] > 0)
		{
			//output item name and quantity
			cout << setw(5) << left << (n) << setw(22) << left << itemNames[i] << " " << 
				setw(4) << right  << itemInv[i] << setw(11) << right << itemSell[i] << endl;
			numOfItems++;
			n++;
		}
	}

	if(numOfItems == 0)
	{
		cout << setw(5) << left << "0" << setw(22) << left << "0" << " " << 
			setw(4) << right  << "0" << setw(11) << right << "0" << endl;
		cout << "\n\nNo items in inventory" << endl;
	}
	return numOfItems;
}

//used to sell inventory
bool Inventory::decrementInv(int x)
{
	if((itemInv[x] - 1) >= 0)
	{
		itemInv[x]--;
		return true;
	}
	else
		return false;
}

//return requiredLevel
int Inventory::getReqLevel(int x)
{
	return reqLevel[x];
}
